﻿/*
This script was created by Visual Studio on 7/9/2008 at 8:23 PM.
Run this script on win-irk7x8hq1km\sqlexpress.YonklyDB.dbo to make it the same as quad-core\sqlexpress.L:\PROJECTS\YONKLY\YONKLY\APP_DATA\YONKLYDB.MDF.dbo.
Please back up your target database before running this script.
*/
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ARITHABORT ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
GO
BEGIN TRANSACTION
GO
PRINT N'Dropping foreign keys from [dbo].[GroupMessages]'
GO
ALTER TABLE [dbo].[GroupMessages] DROP
CONSTRAINT [FK_GroupMessages_GroupMessages],
CONSTRAINT [FK_GroupMessages_Groups],
CONSTRAINT [FK_GroupMessages_aspnet_Users],
CONSTRAINT [FK_GroupMessages_aspnet_Users1]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping foreign keys from [dbo].[Messages]'
GO
ALTER TABLE [dbo].[Messages] DROP
CONSTRAINT [FK_Messages_Messages],
CONSTRAINT [FK_Messages_aspnet_Users],
CONSTRAINT [FK_Messages_aspnet_Users1]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[GroupMessages]'
GO
ALTER TABLE [dbo].[GroupMessages] DROP CONSTRAINT [PK_GroupMessages]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[GroupMessages]'
GO
ALTER TABLE [dbo].[GroupMessages] DROP CONSTRAINT [DF_GroupMessages_IsPrivate]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[GroupMessages]'
GO
ALTER TABLE [dbo].[GroupMessages] DROP CONSTRAINT [DF_GroupMessages_CreatedOn]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[GroupMessages]'
GO
ALTER TABLE [dbo].[GroupMessages] DROP CONSTRAINT [DF_GroupMessages_ModifiedOn]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[Messages]'
GO
ALTER TABLE [dbo].[Messages] DROP CONSTRAINT [PK_Messages]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[Messages]'
GO
ALTER TABLE [dbo].[Messages] DROP CONSTRAINT [DF_Messages_IsPrivate]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[Messages]'
GO
ALTER TABLE [dbo].[Messages] DROP CONSTRAINT [DF_Messages_Type]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[Messages]'
GO
ALTER TABLE [dbo].[Messages] DROP CONSTRAINT [DF_Messages_CreatedOn]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[Messages]'
GO
ALTER TABLE [dbo].[Messages] DROP CONSTRAINT [DF_Messages_ModifiedOn]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[GroupMembers]'
GO
ALTER TABLE [dbo].[GroupMembers] DROP CONSTRAINT [DF_GroupMembers_NotifyOnMessage_1]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[GroupMembers]'
GO
ALTER TABLE [dbo].[GroupMembers] DROP CONSTRAINT [DF_GroupMembers_NotifyOnReply_1]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[GroupMembers]'
GO
ALTER TABLE [dbo].[GroupMembers] DROP CONSTRAINT [DF_GroupMembers_NotifyOnLeave_1]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[GroupMembers]'
GO
ALTER TABLE [dbo].[GroupMembers] DROP CONSTRAINT [DF_GroupMembers_NotifyOnJoin_1]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Dropping constraints from [dbo].[GroupMembers]'
GO
ALTER TABLE [dbo].[GroupMembers] DROP CONSTRAINT [DF_GroupMembers_NotifyOnPending_1]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Rebuilding [dbo].[GroupMessages]'
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
SET XACT_ABORT ON
GO
BEGIN TRANSACTION
CREATE TABLE [dbo].[tmp_ms_xx_GroupMessages]
(
[MessageId] [bigint] NOT NULL IDENTITY(1, 1),
[ParentId] [bigint] NULL,
[GroupId] [bigint] NOT NULL,
[Text] [nvarchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ImageFilename] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ThumbnailFilename] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[SenderId] [uniqueidentifier] NOT NULL,
[RecipientId] [uniqueidentifier] NULL,
[IsPrivate] [bit] NOT NULL CONSTRAINT [DF_GroupMessages_IsPrivate] DEFAULT ((0)),
[Type] [int] NOT NULL CONSTRAINT [DF_GroupMessages_Type] DEFAULT ((0)),
[CreatedOn] [datetime] NOT NULL CONSTRAINT [DF_GroupMessages_CreatedOn] DEFAULT (getdate()),
[ModifiedOn] [datetime] NOT NULL CONSTRAINT [DF_GroupMessages_ModifiedOn] DEFAULT (getdate())
) ON [PRIMARY]
SET IDENTITY_INSERT [dbo].[tmp_ms_xx_GroupMessages] ON
INSERT INTO [dbo].[tmp_ms_xx_GroupMessages]([MessageId], [ParentId], [GroupId], [Text], [SenderId], [RecipientId], [IsPrivate], [CreatedOn], [ModifiedOn]) SELECT [MessageId], [ParentId], [GroupId], [Text], [SenderId], [RecipientId], [IsPrivate], [CreatedOn], [ModifiedOn] FROM [dbo].[GroupMessages]
SET IDENTITY_INSERT [dbo].[tmp_ms_xx_GroupMessages] OFF
DROP TABLE [dbo].[GroupMessages]
EXEC sp_rename N'[dbo].[tmp_ms_xx_GroupMessages]', N'GroupMessages'
COMMIT TRANSACTION
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
GO
PRINT N'Creating primary key [PK_GroupMessages] on [dbo].[GroupMessages]'
GO
ALTER TABLE [dbo].[GroupMessages] ADD CONSTRAINT [PK_GroupMessages] PRIMARY KEY CLUSTERED  ([MessageId]) ON [PRIMARY]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[ViewGroupMessages]'
GO
ALTER VIEW dbo.ViewGroupMessages
AS
SELECT        TOP (100) PERCENT Msgs.MessageId, Msgs.ParentId, Msgs.GroupId, dbo.Groups.Url AS GroupUrl, Msgs.Text, Msgs.ImageFilename, 
                         Msgs.ThumbnailFilename, Msgs.SenderId, Msgs.RecipientId, Msgs.IsPrivate, Msgs.Type, Msgs.CreatedOn, Msgs.ModifiedOn,
                             (SELECT        UserName
                               FROM            dbo.aspnet_Users
                               WHERE        (UserId = Msgs.SenderId)) AS SenderName,
                             (SELECT        Email
                               FROM            dbo.aspnet_Membership
                               WHERE        (UserId = Msgs.SenderId)) AS SenderEmail,
                             (SELECT        UserName
                               FROM            dbo.aspnet_Users AS aspnet_Users_1
                               WHERE        (UserId = Msgs.RecipientId)) AS RecipientName,
                             (SELECT        Email
                               FROM            dbo.aspnet_Membership AS aspnet_Membership_1
                               WHERE        (UserId = Msgs.RecipientId)) AS RecipientEmail,
                             (SELECT        COUNT(MessageId) AS Expr1
                               FROM            dbo.GroupMessages
                               WHERE        (ParentId = Msgs.MessageId)) AS ChildrenCount,
                             (SELECT        UserName
                               FROM            dbo.aspnet_Users AS aspnet_Users_2
                               WHERE        (UserId =
                                                             (SELECT        TOP (1) SenderId
                                                               FROM            dbo.GroupMessages AS Messages_2
                                                               WHERE        (MessageId = Msgs.ParentId)))) AS ParentName
FROM            dbo.GroupMessages AS Msgs INNER JOIN
                         dbo.Groups ON Msgs.GroupId = dbo.Groups.Id
ORDER BY Msgs.CreatedOn DESC
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Rebuilding [dbo].[Messages]'
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
SET XACT_ABORT ON
GO
BEGIN TRANSACTION
CREATE TABLE [dbo].[tmp_ms_xx_Messages]
(
[MessageId] [bigint] NOT NULL IDENTITY(1, 1),
[ParentId] [bigint] NULL,
[Text] [nvarchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ImageFilename] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ThumbnailFilename] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[SenderId] [uniqueidentifier] NOT NULL,
[RecipientId] [uniqueidentifier] NULL,
[IsPrivate] [bit] NOT NULL CONSTRAINT [DF_Messages_IsPrivate] DEFAULT ((0)),
[Type] [int] NOT NULL CONSTRAINT [DF_Messages_Type] DEFAULT ((0)),
[Source] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Messages_Source] DEFAULT ('yonkly'),
[CreatedOn] [datetime] NOT NULL CONSTRAINT [DF_Messages_CreatedOn] DEFAULT (getdate()),
[ModifiedOn] [datetime] NOT NULL CONSTRAINT [DF_Messages_ModifiedOn] DEFAULT (getdate())
) ON [PRIMARY]
SET IDENTITY_INSERT [dbo].[tmp_ms_xx_Messages] ON
INSERT INTO [dbo].[tmp_ms_xx_Messages]([MessageId], [ParentId], [Text], [ImageFilename], [ThumbnailFilename], [SenderId], [RecipientId], [IsPrivate], [Type], [CreatedOn], [ModifiedOn]) SELECT [MessageId], [ParentId], [Text], [ImageFilename], [ThumbnailFilename], [SenderId], [RecipientId], [IsPrivate], [Type], [CreatedOn], [ModifiedOn] FROM [dbo].[Messages]
SET IDENTITY_INSERT [dbo].[tmp_ms_xx_Messages] OFF
DROP TABLE [dbo].[Messages]
EXEC sp_rename N'[dbo].[tmp_ms_xx_Messages]', N'Messages'
COMMIT TRANSACTION
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
GO
PRINT N'Creating primary key [PK_Messages] on [dbo].[Messages]'
GO
ALTER TABLE [dbo].[Messages] ADD CONSTRAINT [PK_Messages] PRIMARY KEY CLUSTERED  ([MessageId]) ON [PRIMARY]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[GroupMembers]'
GO
ALTER TABLE [dbo].[GroupMembers] ALTER COLUMN [NotifyOnMessage] [bit] NOT NULL
ALTER TABLE [dbo].[GroupMembers] ALTER COLUMN [NotifyOnReply] [bit] NOT NULL
ALTER TABLE [dbo].[GroupMembers] ALTER COLUMN [NotifyOnLeave] [bit] NOT NULL
ALTER TABLE [dbo].[GroupMembers] ALTER COLUMN [NotifyOnJoin] [bit] NOT NULL
ALTER TABLE [dbo].[GroupMembers] ALTER COLUMN [NotifyOnPending] [bit] NOT NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[MessageDetails]'
GO
CREATE TABLE [dbo].[MessageDetails]
(
[Id] [bigint] NOT NULL IDENTITY(1, 1),
[MessageId] [bigint] NOT NULL,
[TwitterId] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[TwitterReplyStatusId] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[TwitterReplyUserId] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[TwitterFavorited] [bit] NULL,
[CreatedOn] [datetime] NOT NULL CONSTRAINT [DF_MessageDetails_CreatedOn] DEFAULT (getdate()),
[ModifiedOn] [datetime] NOT NULL CONSTRAINT [DF_MessageDetails_ModifiedOn] DEFAULT (getdate())
) ON [PRIMARY]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_MessageDetails] on [dbo].[MessageDetails]'
GO
ALTER TABLE [dbo].[MessageDetails] ADD CONSTRAINT [PK_MessageDetails] PRIMARY KEY CLUSTERED  ([Id]) ON [PRIMARY]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
exec sp_refreshview N'[dbo].[ViewMessages]'
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding constraints to [dbo].[MessageDetails]'
GO
ALTER TABLE [dbo].[MessageDetails] ADD CONSTRAINT [IX_MessageDetails] UNIQUE NONCLUSTERED  ([MessageId]) ON [PRIMARY]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding constraints to [dbo].[GroupMembers]'
GO
ALTER TABLE [dbo].[GroupMembers] ADD CONSTRAINT [DF_GroupMembers_NotifyOnMessage] DEFAULT ((1)) FOR [NotifyOnMessage]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
ALTER TABLE [dbo].[GroupMembers] ADD CONSTRAINT [DF_GroupMembers_NotifyOnReply] DEFAULT ((1)) FOR [NotifyOnReply]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
ALTER TABLE [dbo].[GroupMembers] ADD CONSTRAINT [DF_GroupMembers_NotifyOnLeave] DEFAULT ((1)) FOR [NotifyOnLeave]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
ALTER TABLE [dbo].[GroupMembers] ADD CONSTRAINT [DF_GroupMembers_NotifyOnJoin] DEFAULT ((1)) FOR [NotifyOnJoin]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
ALTER TABLE [dbo].[GroupMembers] ADD CONSTRAINT [DF_GroupMembers_NotifyOnPending] DEFAULT ((0)) FOR [NotifyOnPending]
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[GroupMessages]'
GO
ALTER TABLE [dbo].[GroupMessages] ADD
CONSTRAINT [FK_GroupMessages_GroupMessages] FOREIGN KEY ([ParentId]) REFERENCES [dbo].[GroupMessages] ([MessageId]),
CONSTRAINT [FK_GroupMessages_Groups] FOREIGN KEY ([GroupId]) REFERENCES [dbo].[Groups] ([Id]) ON DELETE CASCADE,
CONSTRAINT [FK_GroupMessages_aspnet_Users] FOREIGN KEY ([SenderId]) REFERENCES [dbo].[aspnet_Users] ([UserId]) ON DELETE CASCADE,
CONSTRAINT [FK_GroupMessages_aspnet_Users1] FOREIGN KEY ([RecipientId]) REFERENCES [dbo].[aspnet_Users] ([UserId])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Adding foreign keys to [dbo].[Messages]'
GO
ALTER TABLE [dbo].[Messages] ADD
CONSTRAINT [FK_Messages_Messages] FOREIGN KEY ([ParentId]) REFERENCES [dbo].[Messages] ([MessageId]),
CONSTRAINT [FK_Messages_aspnet_Users] FOREIGN KEY ([SenderId]) REFERENCES [dbo].[aspnet_Users] ([UserId]) ON DELETE CASCADE,
CONSTRAINT [FK_Messages_aspnet_Users1] FOREIGN KEY ([RecipientId]) REFERENCES [dbo].[aspnet_Users] ([UserId])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering extended properties'
GO
EXEC sp_updateextendedproperty N'MS_DiagramPane1', N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[26] 4[48] 2[7] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "Msgs"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 133
               Right = 208
            End
            DisplayFlags = 280
            TopColumn = 8
         End
         Begin Table = "Groups"
            Begin Extent = 
               Top = 6
               Left = 246
               Bottom = 123
               Right = 425
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 16
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
', 'SCHEMA', N'dbo', 'VIEW', N'ViewGroupMessages', NULL, NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded.'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed.'
GO
DROP TABLE #tmpErrors
GO
